package me.tuyou.rmi.httpinvoker.server;

import me.tuyou.rmi.httpinvoker.service.MyService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

@SpringBootApplication(scanBasePackages = {
        "me.tuyou.rmi.httpinvoker.server",
})
@EnableWebMvc
public class HttpInvokerServerApp {

    /**
     * spring mvc中以/开头，表示对外提供服务
     * @param myService
     * @return
     */
    @ConditionalOnBean(MyService.class)
    @Bean("/myService")
    public HttpInvokerServiceExporter httpInvokerServiceExporter(MyService myService) {
        HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter();
        exporter.setService(myService);
        exporter.setServiceInterface(MyService.class);
        return exporter;
    }

    public static void main(String[] args) {
        SpringApplication.run(HttpInvokerServerApp.class, args);
    }
}